package com.xyb.controller;

import com.xyb.entity.BizChart;
import com.xyb.service.ChartService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("chart")
public class ChartController {
    @Resource
    private ChartService chartService;

    @GetMapping("charts")
    public List<BizChart> selectBizChart(int status){
        return chartService.selectBizChart(status);
    }

    @PostMapping("chart")
    public String insertBizChart(@RequestBody @Validated(BizChart.insert.class) BizChart bizChart){
        return chartService.insertBizChart(bizChart);
    }

    @PutMapping("chart/status/{chartId}")
    public String updateBizChartStatusByChartId(@PathVariable("chartId") Long chartId,@RequestBody @Validated(BizChart.status.class) BizChart bizChart){
        bizChart.setChartId(chartId);
        return chartService.updateBizChartByChartId(bizChart);
    }
    @PutMapping("chart/{chartId}")
    public String updateBizChartByChartId(@PathVariable("chartId") Long chartId,@RequestBody @Validated(BizChart.update.class) BizChart bizChart){
        bizChart.setChartId(chartId);
        return chartService.updateBizChartByChartId(bizChart);
    }

    @PutMapping("chart/order")
    public String updateBizChartShowOrder(@RequestBody Long[] chartIds){
        return chartService.updateBizChartShowOrder(chartIds);
    }

    @DeleteMapping("chart/{chartId}")
    public String deleteBizChartByChartId(@PathVariable("chartId") Long chartId){
        return chartService.deleteBizChartByChartId(chartId);
    }
}
